/**
 * 
 */
package com.srh.stockmanager.form;

import java.util.ArrayList;
import java.util.List;

import com.srh.stockmanager.entity.Permiso;
import com.srh.stockmanager.entity.User;
import com.srh.stockmanager.enums.TipoPermiso;

/**
 * 
 * @author Sebastian R Helguera (srhelguera@hotmail.com)
 * @version 01/04/2012
 */
public class UserForm {

	private Long		id;

	private String		nombre;

	private String		apellido;

	private String		email;

	private String		telefono;

	private String		pass;

	private String		userName;

	private TipoPermiso	permiso;
	
	private Long		idPermiso;

	/**
	 * 
	 * @return email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * 
	 * @return telefono
	 */
	public String getTelefono() {
		return telefono;
	}

	/**
	 * 
	 * @param email
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * 
	 * @param telefono
	 */
	public void setTelefono(String telefono) {
		this.telefono = telefono;
	}

	/**
	 * 
	 * @return nombre
	 */
	public String getNombre() {
		return nombre;
	}

	/**
	 * 
	 * @return apellido
	 */
	public String getApellido() {
		return apellido;
	}

	/**
	 * 
	 * @param nombre
	 */
	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	/**
	 * 
	 * @param apellido
	 */
	public void setApellido(String apellido) {
		this.apellido = apellido;
	}

	/**
	 * 
	 * @return id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * 
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 
	 * @param userName
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * 
	 * @param pass
	 */
	public void setPass(String pass) {
		this.pass = pass;
	}

	/**
	 * 
	 * @return pass
	 */
	public String getPass() {
		return pass;
	}

	/**
	 * 
	 * @return userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @return the permiso
	 */
	public TipoPermiso getPermiso() {
		return permiso;
	}

	/**
	 * @param permiso
	 *            the permiso to set
	 */
	public void setPermiso(TipoPermiso permiso) {
		this.permiso = permiso;
	}
	
	

	/**
	 * @return the idPermiso
	 */
	public Long getIdPermiso() {
		return idPermiso;
	}

	/**
	 * @param idPermiso the idPermiso to set
	 */
	public void setIdPermiso(Long idPermiso) {
		this.idPermiso = idPermiso;
	}

	/**
	 * 
	 * @param user
	 *            User
	 * @return form UserForm
	 */
	public static UserForm userConvertToForm(User user) {
		UserForm form = new UserForm();

		form.setId(user.getId());
		form.setNombre(user.getNombre());
		form.setApellido(user.getApellido());
		form.setTelefono(user.getTelefono());
		form.setEmail(user.getEmail());
		form.setPass(user.getPass());
		form.setUserName(user.getUserName());
		form.setPermiso(TipoPermiso.fromValue(user.getIdPermiso().getId()));

		return form;
	}

	/**
	 * 
	 * @param form
	 *            UserForm
	 * @return form User
	 */
	public static User userFormConvertToUser(UserForm form) {
		User user = new User();

		user.setId(form.getId());
		user.setNombre(form.getNombre());
		user.setApellido(form.getApellido());
		user.setTelefono(form.getTelefono());
		user.setEmail(form.getEmail());
		user.setPass(form.getPass());
		user.setUserName(form.getUserName());
		Permiso per = new Permiso();
		per.setId(form.getIdPermiso());
		per.setPermiso(TipoPermiso.fromValue(form.getIdPermiso())
				.getPermiso());
		user.setIdPermiso(per);

		return user;
	}

	/**
	 * 
	 * @param userList
	 *            List<User>
	 * @return List<UserForm> formList
	 */
	public static List<UserForm> userListConvertToForm(List<User> userList) {
		List<UserForm> formList = new ArrayList<UserForm>();

		if (null != userList) {
			for (User user : userList) {
				formList.add(userConvertToForm(user));
			}
		}

		return formList;
	}

}
